package com.joysuch.wwyt.openapi.result;

import com.joysuch.wwyt.openapi.constants.ApiCode;
import com.joysuch.wwyt.openapi.constants.ApiStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @program: backend-framework
 * @Description: Api接口异常对象
 * @author: aeiSaf
 * @create: 2020-09-01 10:42
 **/
@Data
@NoArgsConstructor
public class ApiV1Result implements Serializable {

    /**
     * 返回码
     */
    private int code;
    /**
     * 状态
     */
    private String status;
    /**
     * 返回信息
     */
    private String errMsg;
    /**
     * 返回数据
     */
    private Object data;

    public static ApiV1Result success() {
        return new ApiV1Result(ApiCode.API_V1_SUCCESS_CODE, ApiStatus.SUCCESS, null);
    }

    public static ApiV1Result successData(Object data) {
        return new ApiV1Result(ApiCode.API_V1_SUCCESS_CODE, ApiStatus.SUCCESS, data);
    }

    public static ApiV1Result error() {
        return new ApiV1Result(ApiCode.API_V1_ERROR_CODE, ApiStatus.ERROR, null);
    }

    public static ApiV1Result error(String msg) {
        return new ApiV1Result(ApiCode.API_V1_ERROR_CODE, ApiStatus.ERROR, msg, null);
    }
    public static ApiV1Result error(int code ,String msg) {
        return new ApiV1Result(code, ApiStatus.ERROR, msg, null);
    }

    public static ApiV1Result success(Object data) {
        return new ApiV1Result(ApiCode.API_V1_SUCCESS_CODE, ApiStatus.SUCCESS, data);
    }

    public ApiV1Result(int code, String status, Object data) {
        this.code = code;
        this.status = status;
        this.data = data;
    }

    public ApiV1Result(int code, String status, String errMsg, Object data) {
        this.code = code;
        this.status = status;
        this.errMsg = errMsg;
        this.data = data;
    }
}
